import Vue from 'vue'
import Vuex from 'vuex'
// import createPersistedState from 'vuex-persistedstate'

var orginList = []

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    orderList:[],
    user:{}, //获取用户基本信息
    routes:[]   //保存菜单权限
  },
  mutations: {
    setUser(state,user){ 
       //保存用户基本信息
      state.user = user
  },
  setRoutes(state,routes){
          //保存权限路由信息
          state.routes = routes
  },
    // 存出订单管理表格数据
    getOrderList(state, list) {
      orginList = list
      state.orderList = orginList
    },
    // 筛选订单管理的全部
    all(state) {
      state.orderList = orginList
    },

    // 筛选功能 type
    screen(state,type){
      var newList = orginList.filter(item => {
        return item.type === type
      })
      state.orderList = newList
    },
  
    // 订单管理的筛选功能
    searchName(state, keyWorld) {
      var newList = orginList.filter(item => {

        return item.phone.phone.indexOf(keyWorld) !== -1 || item.name.indexOf(keyWorld) !== -1

      })
      state.orderList = newList
    },
    // 取消订单
    cancelOrder(state, id) {
      var newList = []
      for (var i = 0; i < orginList.length - 1; i++) {
        if (orginList[i].id === id) {
          orginList.splice(i, 1)
        }
        newList = orginList
      }
      state.orderList = newList
    },
    // 批量删除
    deleteChange(state,ids){
      var newList = orginList.filter(item=>{
        return ids.indexOf(item.id) === -1   
        })
        state.orderList = newList
        
    },
    // 修改订单
    eidtOrder(state,msg){
      console.log('----',msg)
      let {name,id,money,coursename,phone} = msg
      console.log(phone)
      for(var i = 0 ; i<=orginList.length-1;i++){
        if(orginList[i].id===id){
          orginList[i].name = name
          orginList[i].money = money
          orginList[i].phone=phone
          orginList[i].coursename=coursename
          
        }
      }
    }
  },
  actions: {
  },
  modules: {
  },
  // plugins:[createPersistedState()]

})
